package com.s1nx.back.controller;

import com.s1nx.back.entity.User;
import com.s1nx.back.utils.JwtUtil;
import com.s1nx.back.utils.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {

    private final String USERNAME = "admin";
    private final String PASSWORD = "admin";

    @GetMapping("/login")
    public User login(User user) {
        if (user.getUsername().equals(USERNAME) && user.getPassword().equals(PASSWORD)) {
            user.setToken(JwtUtil.createToken());
            return user;
        } else {
            return null;
        }
    }

    @GetMapping("/checkToken")
    public Result validateToken(String token) {
        System.out.println("token:===>" + token);
        JwtUtil.checkToken(token);
        return Result.withCode(200);
    }

}
